<?php
	
	class Contest { 
		
		private $_db ;

		public function Contest($db) {
			$this->_db = $db ;
		}
		
		public function insert($id, $Coach_Participante_login, $nivel_acesso, $data_inicio, $data_fim) {
			$new_contest = array (
				'id' => $id,
				'Coach_Participante' => $Coach_Participante_login,
				'nivel_acesso' => $nivel_acesso,
				'data_inicio' => $data_inicio,
				'data_fim' => $data_fim
			);

			$this->_db->insert('contest', $new_contest) ;
		}
		
		public function delete($id) {
			$this->_db->delete('contest', 'id = \'' . $id . '\'') ;
		}
		
		public function select_from($cols, $where) {
			
			$this->_db->setFetchMode(Zend_Db::FETCH_OBJ) ;
			$col_str = '' ;
			$len = sizeof($cols) ;
			
			for ($i = 0; $i < $len; $i++) {
				if ($i > 0)
					$col_str .= ',' ;
				$col_str .= $cols[$i] ;
			}
			
			$res = $this->_db->fetchAll('SELECT ' . $col_str . ' FROM contest ' . $where) ;
			return $res ;
		}
		
		public function update($array_cols, $id) {
			$this->_db->update('tag', $array_cols, 'contest = \'' . $login . '\'') ;
		}
		
		public function add_question($id_contest, $id_question) {
			$new_relation = array ( 'Questao_id' => $id_question, 'Contest_id' => $id_contest) ;
			$this->_db->insert('questaocontest', $new_relation) ;
		}
		
		public function delete_question_contest($id_question, $id_contest) {
			$this->_db->delete('questaocontest', 'Questao_id = \'' . $id_question . '\' AND Contest_id = \'' . $id_contest . '\'') ;
		}		
		
		public function add_tag($id_contest, $tag_nome) {
			$new_relation = array ( 'Contest_id' => $id_contest, 'Tag_nome' => $tag_nome) ;
			$this->_db->insert('contesttag', $new_relation) ;			
		}
		
		public function delete_contest_tag($id_contest, $tag) {
			$this->_db->delete('contesttag', 'Contest_id = \'' . $id_contest . '\' AND Tag_nome = \'' . $tag . '\'') ;
		}		
		
		public function add_contest_user($id_contest, $id_participante) {
			$new_relation = array ( 'Contest_id' => $id_contest, 'Participante_login' => $id_participante) ;
			$this->_db->insert('competidorparticipa', $new_relation) ;
		}
		
		
	}

?>